const http = require('http');
const cheerio = require('cheerio');

http.get('http://pic.5tu.cn/photo/rw/rw_nrm.htm', (res) => {

  res.setEncoding('utf8');
  let rawData = '';
  /* 
    浏览器与服务器之间数据传输
    是以 二进制数据流进行分段传输
  */
  let count = 0;
  const imgArr = [];
  res.on('data', (chunk) => {
    rawData += chunk;
  });
  res.on('end', () => {
    const $ = cheerio.load(rawData);
    $('img').each((i, el) => {
      // console.log($(el).attr('src'));
      imgArr.push($(el).attr('src'))
    })
    console.log(imgArr);
  });
}).on('error', (e) => {
  console.error(`Got error: ${e.message}`);
});
